package com.sleep.psy.external_server.business.adjustment.controller;


import com.sleep.psy.external_server.business.adjustment.entity.AdjustmentPlan;
import com.sleep.psy.external_server.business.adjustment.service.AdjustmentPlanService;
import com.sleep.psy.external_server.result.Result;
import com.sleep.psy.external_server.result.ResultEnum;
import com.sleep.psy.external_server.result.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 调节方案 前端控制器
 * </p>
 *
 * @author wenliguo
 * @since 2025-08-12
 */
@Api(tags = {"调节方案"})
@RestController
@RequestMapping("/adjustmentPlan")
public class AdjustmentPlanController {

    protected Logger logger = LoggerFactory.getLogger(AdjustmentPlanDetailsController.class);

    @Autowired
    private AdjustmentPlanService planService;

    /**
     * 通过用户id和测评id获取有效的调节计划
     * @param userId   用户id
     * @param recordId 记录id
     * @return com.sleep.psy.external_server.result.Result<com.sleep.psy.external_server.adjustment.entity.AdjustmentPlan>
     * @author wenliguo
     * @date 2025/8/18 10:33
     */
    @GetMapping("/selectValidPlan")
    @ApiOperation(value = "通过用户id和测评id获取有效的调节计划")
    public Result<AdjustmentPlan> selectValidPlan(@RequestParam("userId") Long userId, @RequestParam("recordId") Long recordId) {

        try {
            return planService.selectValidPlan(userId, recordId);
        } catch (Exception e) {
            logger.error("通过用户id和测评id获取有效的调节计划出错", e);
            return ResultUtil.error(ResultEnum.SERVER_INTERNAL_ERROR);
        }
    }


    /**
     * 通过用户id和获取有效的调节计划
     * @author wenliguo
     * @date 2025/8/25 14:43
     * @param userId
     * @return com.sleep.psy.external_server.result.Result<com.sleep.psy.external_server.business.adjustment.entity.AdjustmentPlan>
    */
    @GetMapping("/selectValidPlanByUserId")
    @ApiOperation(value = "通过用户id获取有效的调节计划")
    public Result<AdjustmentPlan> selectValidPlanByUserId(@RequestParam("userId") Long userId) {

        try {
            return planService.selectValidPlanByUserId(userId);
        } catch (Exception e) {
            logger.error("通过用户id获取有效的调节计划出错", e);
            return ResultUtil.error(ResultEnum.SERVER_INTERNAL_ERROR);
        }
    }
}

